windingMaterialCoefficient = 235;
if (form.windingMaterial === '铝导线') {
  windingMaterialCoefficient = 225;
}
total = {};
// for (item in form.testData) {
form.testData.forEach((item, index) => {
  ops = ['value'];
  try {
    ops.forEach((v, i) => {
      item[v] = parseFloat(item[v]);
    });
    item.value75 =
      item.value *
      ((windingMaterialCoefficient + 75) /
        (windingMaterialCoefficient + form.oilTemper));
    item.his75 = parseFloat(item.his75Show);
    item.diff1 = ((item.value75 - item.his75) / item.his75) * 100;
    if (!total[item.gearNumber]) {
      total[item.gearNumber] = {};
    }
    item.value75Show = item.value75.toFixed(3);
    item.diff1Show = item.diff1.toFixed(3);

    total[item.gearNumber][item.oabc.toLowerCase()] = item.value;
  } catch (error) {
    console.error(error);
  }
});
// for diff2
avg = (array) => array.reduce((a, b) => a + b) / array.length;
Object.keys(total).forEach((gearNumber, i) => {
  try {
    arr = Object.values(total[gearNumber]);
    fillingItem = form.testData.find((e) => {
      return (
        '' + e.gearNumber === '' + gearNumber &&
        (e.oabc.toLowerCase() === 'ob' || e.oabc.toLowerCase() === 'bc')
      );
    });
    fillingItem.diff2 =
      ((Math.max(...arr) - Math.min(...arr)) / avg(arr)) * 100;
    fillingItem.diff2Show = fillingItem.diff2.toFixed(3);
  } catch (error) {
    console.error(error);
  }
});

// for word tpl
form.wordTestData = {};
highItems = {};
equalf = (e, gearNumber, oabc) => {
  return (
    '' + e.gearNumber === '' + gearNumber && e.oabc.toLowerCase() === '' + oabc
  );
};
if (form.highSideWinding) {
  for (
    gearNumber = form.gearsStartNumber;
    gearNumber < form.gearsEndNumber + 1;
    gearNumber++
  ) {
    oa = form.testData.find((e) => equalf(e, gearNumber, 'oa'));
    ob = form.testData.find((e) => equalf(e, gearNumber, 'ob'));
    oc = form.testData.find((e) => equalf(e, gearNumber, 'oc'));
    item = {
      oa: oa.value,
      ob: ob.value,
      oc: oc.value,
      oa75: oa.value75,
      ob75: ob.value75,
      oc75: oc.value75,
      hisoa75: oa.his75,
      hisob75: ob.his75,
      hisoc75: oc.his75,
      diffoa: oa.diff1,
      diffob: ob.diff1,
      diffoc: oc.diff1,
      diff: ob.diff2,
    };
    highItems[gearNumber] = item;
  }
  form.wordTestData.highSideWinding = highItems;
}
if (form.lowSideWinding) {
  gearNumber = '低压侧';
  oa = form.testData.find((e) => equalf(e, gearNumber, 'ab'));
  ob = form.testData.find((e) => equalf(e, gearNumber, 'bc'));
  oc = form.testData.find((e) => equalf(e, gearNumber, 'ca'));
  item = {
    oa: oa.value,
    ob: ob.value,
    oc: oc.value,
    oa75: oa.value75,
    ob75: ob.value75,
    oc75: oc.value75,
    hisoa75: oa.his75,
    hisob75: ob.his75,
    hisoc75: oc.his75,
    diffoa: oa.diff1,
    diffob: ob.diff1,
    diffoc: oc.diff1,
    diff: ob.diff2,
  };
  form.wordTestData.lowSideWinding = item;
}
